package com.yanqu.road.server.cmd.activity.selectlottery;

import com.yanqu.road.entity.activity.selectlottery.data.SelectLotteryUserData;
import com.yanqu.road.exception.BusinessException;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.ApprenticeProto;
import com.yanqu.road.pb.activity.SelectLotteryProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.CmdApi;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.apprentice.ApprenticeModule;
import com.yanqu.road.server.gameplayer.module.activity.selectlottery.SelectLotteryModule;
import com.yanqu.road.server.manger.activity.monjinlottery.pb.SelectLotteryPb;
import com.yanqu.road.server.protocol.Protocol;

@CmdApi(reqMsg = SelectLotteryProto.SelectLotteryEnterActivityReqMsg.class, respMsg = SelectLotteryProto.SelectLotteryEnterActivityRespMsg.class)
@Cmd(code = Protocol.S_SELECT_LOTTERY_ENTER_ACTIVITY, desc = "通用自选抽奖-进入活动")
public class SelectLotteryEnterActivityCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        SelectLotteryProto.SelectLotteryEnterActivityReqMsg reqMsg = SelectLotteryProto.SelectLotteryEnterActivityReqMsg.parseFrom(packet.getBytes());
        SelectLotteryProto.SelectLotteryEnterActivityRespMsg.Builder respMsg = SelectLotteryProto.SelectLotteryEnterActivityRespMsg.newBuilder();
        try {
            //进入活动
            SelectLotteryUserData userData = player.getModule(SelectLotteryModule.class).enterActivity(reqMsg.getActivityId());
            respMsg.setRet(0);
            respMsg.setUserData(SelectLotteryPb.buildSelectLotteryUserData(userData));
        } catch (BusinessException e) {
            respMsg.setRet(e.getCode());
        }
        player.sendPacket(Protocol.U_SELECT_LOTTERY_ENTER_ACTIVITY, respMsg);
    }

    @Override
    public void sendData(GamePlayer player) {}
}
